package com.ruoyi.ww.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ww.domain.vo.BsWwsyVo;
import com.ruoyi.ww.domain.bo.BsWwsyBo;
import com.ruoyi.ww.service.IBsWwsyService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 外委试验信息主
 *
 * @author zyb
 * @date 2024-08-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ww/bsWwsy")
public class BsWwsyController extends BaseController {

    private final IBsWwsyService iBsWwsyService;

    /**
     * 查询外委试验信息主列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<BsWwsyVo> list(BsWwsyBo bo, PageQuery pageQuery) {
        return iBsWwsyService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出外委试验信息主列表
     */
    @SaCheckLogin
    @Log(title = "外委试验信息主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BsWwsyBo bo, HttpServletResponse response) {
        List<BsWwsyVo> list = iBsWwsyService.queryList(bo);
        ExcelUtil.exportExcel(list, "外委试验信息主", BsWwsyVo.class, response);
    }

    /**
     * 获取外委试验信息主详细信息
     *
     * @param wwsyId 主键
     */
    @SaCheckLogin
    @GetMapping("/{wwsyId}")
    public R<BsWwsyVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long wwsyId) {
        return R.ok(iBsWwsyService.queryById(wwsyId));
    }

    /**
     * 新增外委试验信息主
     */
    @SaCheckLogin
    @Log(title = "外委试验信息主", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BsWwsyBo bo) {
        return toAjax(iBsWwsyService.insertByBo(bo));
    }

    /**
     * 修改外委试验信息主
     */
    @SaCheckLogin
    @Log(title = "外委试验信息主", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BsWwsyBo bo) {
        return toAjax(iBsWwsyService.updateByBo(bo));
    }

    /**
     * 删除外委试验信息主
     *
     * @param wwsyIds 主键串
     */
    @SaCheckLogin
    @Log(title = "外委试验信息主", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wwsyIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] wwsyIds) {
        return toAjax(iBsWwsyService.deleteWithValidByIds(Arrays.asList(wwsyIds), true));
    }
}
